package com.konsung.network;

import android.content.Context;
import android.text.TextUtils;

import com.konsung.bean.MeasureDataBean;
import com.konsung.bean.PatientBean;
import com.konsung.provide.ProviderReader;
import com.konsung.util.DBDataUtil;
import com.konsung.util.UiUtils;
import com.konsung.util.constant.GlobalConstant;

/**
 * Created by YYX on 2016/6/7 0007.
 * 上传到云平台的类
 */
public class UploadCloudMeasureData implements BaseUpload {
    private static UploadCloudMeasureData instance = null;

    /**
     * 返回当前用户的实例的方法
     * @return UploadCloudMeasureData
     */
    public static UploadCloudMeasureData newInstance() {
        if (instance == null) {
            instance = new UploadCloudMeasureData();
        }
        return instance;
    }

    /**
     * 根据测量记录上传病人
     * @param context context
     * @param bean 测量记录
     * @param data 测量信息
     */

    @Override
    public void uploadPhysicalMeasure(final Context context, final PatientBean bean,
            final MeasureDataBean data) {
        UiUtils.postShortThread(new Runnable() {
            @Override
            public void run() {
                // 命名空间
                String nameSpace = "http://webservice/";

                // 调用的方法名称
                String methodName = "WebVillageHealth";

                // EndPoint

                String path = ProviderReader.getUploadCloudPath(context);
                if (TextUtils.isEmpty(path)) {
                    return;
                }
                if (!path.contains(GlobalConstant.CLOUD_EXT)) {
                    path = path + GlobalConstant.CLOUD_EXT;
                }
                //拼接上传字段
                String checkData = DBDataUtil.getXmlData(context, bean, data);
                try {
                    WsHandler.upLoadToServer(checkData, nameSpace, methodName, path);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
